using LegoBotPrimaAbstractions;

namespace LegoBotPrima.Actions
{
    public abstract class StepBotAction : BotAction
    {
        protected abstract void StartMoving(ILegoBotPrimaWorkflow workflow);
        protected abstract int StopAfterTicks { get; }

        private static readonly object _synch_OnTimerTick = new object();

        public override void Initialize()
        {
            StartMoving(Workflow);
        }

        private int _tickNumber;
        public override void OnTimerTick(int tickNimber)
        {
            lock (_synch_OnTimerTick)
            {
                this._tickNumber++;

                if (this._tickNumber >= StopAfterTicks)
                {
                    Workflow.Stop();
                    Workflow.EndAction(this);
                }
            }
        }
    }
}